<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
// Include libraries 
	
//assign root directory to the inc.php	
//$root_dir=dirname(__FILE__);				
//require_once 'lib/inc.php';					
error_log(E_ALL);

$SEMF_ROOT = '../';
$project_dir = (isset($_GET["project_dir"]))?$_GET["project_dir"]:$_POST["project_dir"];
$YUI_ROOT='../lib/yui/';

//for the semf_root..
$semf_root = "../";
$from_url = "project_home/index.php";
include("../core/lib/login_checker.php");

$module_name = $_POST["module_name"];
$from_page_designer = $_POST["from_page_designer"];

$project_name = (isset($_GET["project_name"]))?$_GET["project_name"]:$_POST["project_name"];
$user_token = (isset($_GET["user_token"]))?$_GET["user_token"]:$_POST["user_token"];

// aqua and winxp style library for panels
require_once ($SEMF_ROOT.'/lib/style_select.php');


?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Database Schema</title>

<script>
//very initial things..
SEMF = {};
</script>

<link type="text/css" rel="stylesheet" href="<?php echo $YUI_ROOT ?>build/container/assets/container.css">
<link type="text/css" rel="stylesheet" href="<?php echo $YUI_ROOT ?>build/fonts/fonts.css">
<link type="text/css" rel="stylesheet" href="<?php echo $YUI_ROOT ?>build/reset/reset.css">
<link rel="shortcut icon" href="<?php echo $SEMF_ROOT?>icons/semf.ico" />
<!-- CSS for Button -->
<link rel="stylesheet" type="text/css" href="<?php echo $YUI_ROOT ?>build/button/assets/button.css">

<!-- CSS for tree -->
<link rel="stylesheet" type="text/css" href="<?php echo $SEMF_ROOT ?>styles/tree.css" />
<style>

.module_link {
	background-image:url(../lib/images/menuidle2.png);
	background-repeat:repeat-x;
	height:15px;
	font-size:12px;
	margin-top:1px;
	font-family:Geneva, Arial, Helvetica, sans-serif ;
	font-weight: bolder;
	color: #000000;
	vertical-align: middle;
	padding: 3px 3px 3px 6px;
}
.module_link:hover{
 background-image:url(../lib/images/menubg2.png);
 background-repeat:repeat-x;
 padding-left: 10px;
 font-size: 14px;
 
}
.module_link:active{
 background-image:url(../lib/images/activemenu.png);
 background-repeat:repeat-x;
}
.bd a {
 text-decoration:none;
 text-transform:capitalize;
 
}
.bd a:hover {
 text-shadow:#999999;
}
</style>
<?php
//set skin types for the panel -- don't move this anyware --
skin("aqua",'panel1');
skin("aqua",'panel2');
skin("aqua",'inputDialog');
skin("aqua",'alertDialog');
skin("aqua",'sampleDirPanel');
?>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/event/event.js" ></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/animation/animation.js"></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/connection/connection.js"></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/dom/dom.js" ></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/container/container.js"></script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/dragdrop/dragdrop.js"> </script>
<script type="text/javascript" src="<?php echo $YUI_ROOT ?>build/treeview/treeview.js"></script>

<script type="text/javascript" src="<?php echo $SEMF_ROOT ?>lib/connect.js"> </script>
<script type="text/javascript" src="<?php echo $SEMF_ROOT ?>lib/style.js"></script>
<script>
YAHOO.namespace("schema.container");
// BEGIN RESIZEPANEL SUBCLASS //
				YAHOO.widget.ResizePanel = function(el, userConfig) {
					if (arguments.length > 0) {
						YAHOO.widget.ResizePanel.superclass.constructor.call(this, el, userConfig);
					}
				}

				YAHOO.extend(YAHOO.widget.ResizePanel, YAHOO.widget.Panel);

				YAHOO.widget.ResizePanel.CSS_PANEL_RESIZE = "resizepanel";

				YAHOO.widget.ResizePanel.CSS_RESIZE_HANDLE = "resizehandle";

				YAHOO.widget.ResizePanel.prototype.init = function(el, userConfig) {
					YAHOO.widget.ResizePanel.superclass.init.call(this, el);
					this.beforeInitEvent.fire(YAHOO.widget.ResizePanel);

					YAHOO.util.Dom.addClass(this.innerElement, YAHOO.widget.ResizePanel.CSS_PANEL_RESIZE);

					this.resizeHandle = document.createElement("DIV");
					this.resizeHandle.id = this.id + "_r";
					this.resizeHandle.className = YAHOO.widget.ResizePanel.CSS_RESIZE_HANDLE;
						
                    this.beforeShowEvent.subscribe(function() {

                        this.body.style.overflow = "auto";
                    
                    }, this, true);


                    this.beforeHideEvent.subscribe(function() {

                        /*
                             Set the CSS "overflow" property to "hidden" before
                             hiding the panel to prevent the scrollbars from 
                             bleeding through on Firefox for OS X.
                        */

                        this.body.style.overflow = "hidden";
                    
                    }, this, true);


					this.beforeRenderEvent.subscribe(function() {

                        /*
                             Set the CSS "overflow" property to "hidden" by
                             default to prevent the scrollbars from bleeding
                             through on Firefox for OS X.
                        */

                        this.body.style.overflow = "hidden";

                        if (! this.footer) {
                            this.setFooter("");
                        }

                    }, this, true);

					this.renderEvent.subscribe(function() {
						var me = this;
						
						me.innerElement.appendChild(me.resizeHandle);

						this.ddResize = new YAHOO.util.DragDrop(this.resizeHandle.id, this.id);
						this.ddResize.setHandleElId(this.resizeHandle.id);

						var headerHeight = me.header.offsetHeight;

						this.ddResize.onMouseDown = function(e) {

							this.startWidth = me.innerElement.offsetWidth;
							this.startHeight = me.innerElement.offsetHeight;
							
							me.cfg.setProperty("width", this.startWidth + "px");
							me.cfg.setProperty("height", this.startHeight + "px");

							this.startPos = [YAHOO.util.Event.getPageX(e),
											 YAHOO.util.Event.getPageY(e)];

							me.innerElement.style.overflow = "hidden";
							me.body.style.overflow = "auto";
						}
						
						this.ddResize.onDrag = function(e) {
							var newPos = [YAHOO.util.Event.getPageX(e),
										  YAHOO.util.Event.getPageY(e)];
							
							var offsetX = newPos[0] - this.startPos[0];
							var offsetY = newPos[1] - this.startPos[1];
					
							var newWidth = Math.max(this.startWidth + offsetX, 10);
							var newHeight = Math.max(this.startHeight + offsetY, 10);

							me.cfg.setProperty("width", newWidth + "px");
							me.cfg.setProperty("height", newHeight + "px");

							var bodyHeight = (newHeight - 5 - me.footer.offsetHeight - me.header.offsetHeight - 3);
							if (bodyHeight < 0) {
								bodyHeight = 0;
							}

							me.body.style.height =  bodyHeight + "px";

							var innerHeight = me.innerElement.offsetHeight;
							var innerWidth = me.innerElement.offsetWidth;

							if (innerHeight < headerHeight) {
								me.innerElement.style.height = headerHeight + "px";
							}

							if (innerWidth < 20) {
								me.innerElement.style.width = "20px";
							}
						}

					}, this, true);

					if (userConfig) {
						this.cfg.applyConfig(userConfig, true);
					}

					this.initEvent.fire(YAHOO.widget.ResizePanel);
				};

				YAHOO.widget.ResizePanel.prototype.toString = function() {
					return "ResizePanel " + this.id;
				};
				
				// END RESIZEPANEL SUBCLASS //


function init(){
		YAHOO.schema.container.panel1 = new YAHOO.widget.ResizePanel("panel1",{width:"250px",height:"600px",xy:[5,5],visible:true,close:false,draggable:false,modal:true} );
		YAHOO.schema.container.panel1.render();
		
		YAHOO.schema.container.panel2 = new YAHOO.widget.ResizePanel("panel2",{width:"700px",height:"600px",xy:[260,5],close:false,draggable:false,modal:true});
		YAHOO.schema.container.panel2.render();	
		
		
		//create the dialog
	YAHOO.schema.container.inputDialog = new YAHOO.widget.Dialog("inputDialog",{ width : "300px",
															  fixedcenter : true,
															  visible : false, 
															  constraintoviewport : true,modal:true
															 } );

	//create the alert dialog
	YAHOO.schema.container.alertDialog = new YAHOO.widget.Dialog("alertDialog",{ width : "300px",
															  fixedcenter : true,
															  visible : false, 
															  constraintoviewport : true,modal:true
															 } );

	// Wire up the success and failure handlers
	YAHOO.schema.container.inputDialog.render(document.body);	
	YAHOO.schema.container.alertDialog.render(document.body);
}

// call init after window is loaded
YAHOO.util.Event.addListener(window,"load",init);
</script>
</head>
<body>
<!--
Starting definition of panel 1
//-->
<div id="panel1">
  <div class="hd">
    <div class="tl"></div>
    <span>Set of Modules</span>
    <div class="tr"></div>
  </div>
  <div class="bd"  style="height:550px;overflow:auto">
   <img title="Back" style="cursor:pointer" 
  		onclick="redirectPage('redirect_token');"
		width="25" height="25" src="../lib/images/back1.png"  /> 
   <img title="Remove Modules" style="cursor:pointer" 
  		onclick="javascript:removeModule('<?php echo $project_name?>', '<?php echo $project_dir?>');"
		width="25" height="25" src="../lib/images/close.png"  /> 
	<img title="Add Modules" style="cursor:pointer" 
  		onclick="javascript:addModuleMode('<?php echo $project_name?>', '<?php echo $project_dir?>');"
		width="25" height="25" src="../lib/images/add.png"  /> 
	<img title="Export Modules" width="25" height="25" style="cursor:pointer"
		onclick="javascript:upModule('<?php echo $project_name?>', '<?php echo $project_dir?>');"
		src='../lib/images/up.png' /> 
	<img title="Import Modules" width="25" height="25"  style="cursor:pointer"
		onclick="javascript:downModule('<?php echo $project_name?>', '<?php echo $project_dir?>');"
		src='../lib/images/down.png' /> 
	<img title="Manual" width="25" height="25" style="cursor:pointer"
		onclick="window.location.href='../man/manual.htm'";
		src='../lib/images/help.png' />
	<img title="Logout" width="25" height="25" style="cursor:pointer"
		onclick="window.location.href='../core/login.php'"
		src='../images/logout.png' />
    <div id="moduleListPanel">
      <?php
		include("../lib/modules/list_modules.php");
	?>
    </div>
    <br />
  </div>
  <div class="ft">
    <div class="bl"></div>
    <span>&copy;SEMF</span>
    <div class="br"></div>
  </div>
</div>
<!--
Starting definition of panel 2
//-->
<div id="panel2" >
  <div class="hd" id="panel2_hd">
    <div class="tl"></div>
    <span></span>
    <div class="tr"></div>
  </div>
  <div class="bd" style="height:550px;overflow:auto">
    <div id="breadcrumb"> </div>
    <div id="panel2_content"><img style="  padding:100px;" src="../images/titlelogo.png" alt="SEMF"/> </div>
  </div>
  <div class="ft"> <span> Web Designing Framework For Sport Event Management(SEMF) &copy; 2007 </span> </div>
</div>
<div id="inputDialog">
  <div class="hd" id="">
    <div class="tl"></div>
    <span id="dialogheader"> </span>
    <div class="tr"></div>
  </div>
  <div class="bd" id="dialogbody">
    <form name="form1" method="POST"  id="inputform">
      <label for="name">Input name</label>
      <input type="text" name="name" />
    </form>
  </div>
  <div class="ft"></div>
</div>
<div id="alertDialog" >
  <div class="hd">
    <div class="tl"></div>
    <span id="alertheader"> </span>
    <div class="tr"></div>
  </div>
  <div class="bd" id="alertbody"></div>
  <div class="ft"></div>
</div>
<iframe id="mainIframe" style="visibility:hidden">
</iframe>
<div id="redirectFormContainer">
</div>

<div id="sampleDirPanel">
<div id="sampleDirPanelHeader" class="hd">
    <div class="tl"></div>
	<div id="sampleDirPanelTitle">Find Project Directory</div>
    <div class="tr"></div>
</div>
<div id="sampleDirPanelView" class="bd" style="width:98% position:absolute;" >
	<iframe id="sampleDirPanelFrame" style="border:none;width:100%; height:340px; overflow:auto" src="../core/lib/dir_list.php?dir_root=samples&dir_root_path=./&dirs_only=1">
	</iframe>
</div>
<div id="sampleDirPanelFooter" class="ft"></div>
</div>

<input type="hidden" id="user_token_input" value="<?php echo $user_token; ?>" />
<input type="hidden" id="project_dir_input" value="<?php echo $project_dir; ?>" />
<input type="hidden" id="module_name_input" value="<?php echo $module_name; ?>" />
<input type="hidden" id="table_name_input" value="<?php echo $table_name; ?>" />

<script>
<?php
if($from_page_designer == 1)
{
	echo "getModulePageData('${module_name}', '${project_dir}');\n";
}
?>
initPageDesigner();
function initPageDesigner()
{
	SEMF.sampleDirPanel = new YAHOO.widget.Panel("sampleDirPanel",  { 
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
		
		width:"550px", height:"380px",
		  underlay:"shadow",   fixedcenter: true,
				close:true, visible:false, draggable:true, modal:true } 
		);
	SEMF.sampleDirPanel.render();
}
</script>
<form id="redirect_token" action="<?php echo $SEMF_ROOT ?>index.php"  method="post">
<input type="hidden" id="user_token" name="user_token" value="<?php echo $user_token; ?>" />
<input type="hidden" id="project_dir" name="project_dir" value="<?php echo $project_dir ?>" />
</form>
</body>
</html>
